<template>
	<view style="padding: 30rpx;">
		<view class="new-item" v-for="(item,index) in list" :key="index" @click="goToUrl('/pages/news/news-info?id='+item.id)">
			<view class="new-item-left">
				<view class="new-item-title">{{item.title}}</view>
				<view class="new-item-time">{{item.createtime}}</view>
			</view>
			<image class="new-item-image" :src="item.image" mode=""></image>
		</view>
		<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" width="150px"
			height="150px" text="列表为空" textSize="18">
		</u-empty>
		<view style="padding-bottom: 100rpx;">
			<u-loadmore v-if="loading" status="loading" />
			<u-loadmore v-if="isLastPage" status="nomore" />
		</view>
		<!-- <view class=""></view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getNewsList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getNewsList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getNewsList();
			} else {
				this.isLastPage = true
			}
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.goodsList.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getNewsList();
			} else {
				this.isLastPage = true
			}
		},
		methods: {
			goToUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
			getNewsList() {
				this.$api.newsList({
					page: this.page,
					limit: this.limit
				}).then(res => {
					this.list = [...this.list, ...res.data]
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.new-item-left{
		flex: 1;
	}
	.new-item-time {
		font-size: 13px;
		color: #999999;
	}

	.new-item-title {
		font-size: 15px;
		color: #000000;
		margin-bottom: 30rpx;
		flex: 1;
		-webkit-line-clamp: 2; // 设置两行文字溢出
		display: -webkit-box;
		/** 对象作为伸缩盒子模型显示 **/
		-webkit-box-orient: vertical;
		/** 设置或检索伸缩盒对象的子元素的排列方式 **/
		overflow: hidden;
		/** 隐藏超出的内容 **/
	}

	.new-item {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		margin-bottom: 30rpx;
	}

	.new-item-image {
		width: 180rpx;
		height: 180rpx;
		flex-shrink: 0;
		margin-left: 20rpx;
	}
</style>